package interfaces.pattren.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserProxy implements InvocationHandler {
	private Object object;
	
	public UserProxy(Object object) {
		super();
		this.object = object;
	}
	
	public Object getProxy(){
		return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), object.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object arg0, Method method, Object[] args) throws Throwable {
		System.out.println("进入代理方法----------");
		System.out.println("method:" + method.toString());
		System.out.println("退出代理方法----------");
		return method.invoke(object, args);
	}

}
